package q121_maxProfit;

public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.maxProfit(new int[]{7,6,4,3,2,1}));
    }

    public int maxProfit(int[] prices) {
        int res = 0;
        int low = prices[0];
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < low) {
                low = prices[i];
            }
            res = Math.max(res, prices[i] - low);
        }

        return res;
    }
}
